package com.gxa.controller.zhy;

import com.gxa.common.R;
import com.gxa.common.ResponseData;
import com.gxa.pojo.Permission;
import com.gxa.pojo.Users;
import com.gxa.pojo.zhy.Pr;
import com.gxa.service.LoginService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: 赵贺益
 * Date: 2021/12/02 15:45
 * Description:
 * Version: V1.0
 */
//@Transactional(rollbackFor = {Exception.class})
//@Transactional
@Controller
@Api(value ="用于动态生成左侧菜单" ,tags = "主界面的接口")
@RequestMapping("/queryMainInterface")
public class MainInterfaceController {
    @Autowired
    private LoginService loginService;


     @RequestMapping(value ="queryPermissionbyrole_id" ,method = RequestMethod.POST)
     @ResponseBody
     @ApiOperation(value = "获取菜单接口",notes = "获取到的就是一个对象",httpMethod = "POST", response = R.class)
     @ApiImplicitParams({
             @ApiImplicitParam(name = "username",value = "登录的账号(要根据登录的账号获取密码)" ,required = true,paramType = "query"),
                })
     @ApiResponses({
             @ApiResponse(code=200,message = "获取菜单成功"),
             @ApiResponse(code =401,message = "获取菜单失败"),
             @ApiResponse(code = 500,message = "后台服务错误")
     })


     public R queryPermissionbyrole_id(@RequestBody Users users){
         String username=users.getUsername();
         R r=loginService.queryPermissionbyUsername(username);
         return r;
     }
    @RequestMapping(value ="queryPermissionListByUsername" ,method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取该用户所有的可以操作的二级菜单的接口",notes = "获取到的就是一个对象",httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username",value = "登录的账号" ,dataType = "String",required = true,paramType = "query"),
               })
    @ApiResponses({
            @ApiResponse(code=200,message = "查询成功"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
     public  R queryPermissionListByUsername(String username){
         R r=new R();
        List<Permission> permissionList=loginService.queryPermissionByUsername(username);
         r.setCode(200);
         r.setMsg("查询成功");
         r.setData(permissionList);
         return r;
     }


}
